package com.test;

/*
public class Example03 {
    public static void main(String[] args) {
        System.out.println("----------1 添加----------");
        add();
        System.out.println("----------2 删除----------");
        remove();
        System.out.println("----------3 修改----------");
        alter();
        System.out.println("----------4 截取----------");
        sub();
    }

    public static void add() {
        StringBuffer sb = new StringBuffer(); //定义一个字符串缓冲区
        sb.append("abcdefg");   //在末尾添加字符串
        sb.append("hij").append("klmn");    //练习调用append()方法添加字符串
        System.out.println("append添加结果:" + sb);
        sb.insert(2, "123"); //在指定位置插入字符串
        System.out.println("insert添加结果:" + sb);
    }

    public static void remove() {
        StringBuffer sb = new StringBuffer("abcdefg");
        sb.delete(1, 5); //指定范围删除
        System.out.println("删除指定范围结果:" + sb);
        sb.deleteCharAt(2); //指定位置删除
        System.out.println("删除指定位置结果:" + sb);
        sb.delete(0, sb.length());   //清空字符串缓冲区
        System.out.println("清空缓冲区结果:" + sb);
    }

    public static void alter() {
        StringBuffer sb = new StringBuffer("abcedf");
        sb.setCharAt(1, 'p');    //定义一个字符串缓冲区
        System.out.println("修改指定位置字符结果：" + sb);
        sb.replace(1, 3, "qq");
        System.out.println("字符串反转结果:" + sb.reverse());
    }

    public static void sub() {
        StringBuffer sb = new StringBuffer();
        System.out.println("获取sb的初始容量" + sb.capacity());
        sb.append("itcast123");
        System.out.println("append添加结果:" + sb);
        System.out.println("截取第7~9个字符:" + sb.substring(6, 9));
    }

}

 */

/*
public class Example03 {
    public static void main(String[] args) {
        int[] fromArray = {10, 11, 12, 13, 14, 15}; // 源数组
        int[] toArray = {20, 21, 22, 23, 24, 25, 26, 27}; // 目标数组
        System.arraycopy(fromArray, 2, toArray, 3, 4);//复制数组元素

        System.out.println("复制后的数组元素为:");
        for (int i = 0; i < toArray.length; i++) {
            if (i < toArray.length - 1) {
                System.out.print(toArray[i] + ",");
            } else
                System.out.println(toArray[i]);
        }
    }
}

 */

/*
public class Example03 {
    public static void main(String[] args) {
        long startTime = System.currentTimeMillis();  //循环开始时的当前时间
        int sum = 0;
        for (int i = 0; i < 1000000000; i++) {
            sum+=1;
        }
        long endTime = System.currentTimeMillis();  //循环结束后的当前时间
        System.out.println("程序运行的时间为:"+(endTime-startTime)+"ms");
    }
}


 */

/*
import java.util.Enumeration;
import java.util.Properties;

public class Example03 {
    public static void main(String[] args) {
        // 获取当前系统属性
        Properties properties = System.getProperties();
        // 获取所有系统属性的key，返回Enumeration对象
        Enumeration propertyNames = properties.propertyNames();
        while (propertyNames.hasMoreElements()) {
            // 获取系统属性的键key
            String key = (String) propertyNames.nextElement();
            // 获取当前键key对应的值value
            String value = System.getProperty(key);
            System.out.println(key + "--->" + value);
        }
    }
}

 */


/*
public class Example03 {
    public static void main(String[] args) {
        Runtime rt = Runtime.getRuntime(); // 创建Runtime对象
        System.out.println("处理器的个数: " + rt.availableProcessors()+"个");
        System.out.println("空闲内存数量: " + rt.freeMemory() / 1024 / 1024
                + "MB");
        System.out.println("最大可用内存数量: " + rt.maxMemory() / 1024 /
                1024 + "MB");
        System.out.println("内存总容量: " + rt.totalMemory() / 1024 /
                1024 + "MB");
    }
}


 */

/*
public class Example03 {
    public static void main(String[] args) {
        System.out.println("计算-10的绝对值: " + Math.abs(-10));
        System.out.println("求大于5.6的最小整数: " + Math.ceil(5.6));
        System.out.println("求小于-4.2的最大整数: " + Math.floor(-4.2));
        System.out.println("对-4.6进行四舍五入: " + Math.round(-4.6));
        System.out.println("求2.1和-2.1中的较大值: " + Math.max(2.1, -2.1));
        System.out.println("求2.1和-2.1中的较小值: " + Math.min(2.1, -2.1));
        System.out.println("生成一个大于等于0.0小于1.0随机值: " +
                Math.random());
        System.out.println("计算1.57的正弦结果: " + Math.sin(1.57));
        System.out.println("计算4的开平方的结果: " + Math.sqrt(4));
        System.out.println("计算指数函数2的3次方的值: " + Math.pow(2, 3));
    }
}

 */

/*
import java.util.Random;

public class Example03{
    public static void main(String[] args){
        Random random=new Random();   //不传入种子

        for(int i=0; i<10;i++) {
            System.out.println(random.nextInt(0,100));
        }
    }
}

 */

/*
import java.util.Random;

public class Example03 {
    public static void main(String args[]) {
        Random r = new Random(13); // 创建对象时传入种子
        // 随机产生10个[0,100)之间的整数
        for (int x = 0; x < 10; x++) {
            System.out.println(r.nextInt(100));
        }
    }
}


 */


/*
import java.util.Random;

public class Example03 {
    public static void main(String[] args) {
        Random r = new Random();     //创建Random实例对象
        System.out.println("生成boolean类型的随机数:" + r.nextBoolean());
        System.out.println("生成float类型的随机数:" + r.nextFloat());
        System.out.println("生成double类型的随机数:" + r.nextDouble());
        System.out.println("生成int类型的随机数:" + r.nextInt());
        System.out.println("生成0~100之间int类型的随机数:" + r.nextInt(100));
        System.out.println("生成long类型的随机数:" + r.nextLong());

    }
}

 */


/*
import java.math.BigInteger;

public class Example03 {
    public static void main(String[] args) {
        BigInteger bi1 = new BigInteger("123456789");
        BigInteger bi2 = new BigInteger("987654321");
        System.out.println("bi2与bi1的和: " + bi2.add(bi1));
        System.out.println("bi2与bi1的差: " + bi2.subtract(bi1));
        System.out.println("bi2与bi1的积: " + bi2.multiply(bi1));
        System.out.println("bi2与bi1的商: " + bi2.divide(bi1));
        System.out.println("bi2与bi1之间的较大值: " + bi2.max(bi1));
        System.out.println("bi2与bi1之间的较小值: " + bi2.min(bi1));
        //创建BigInteger数组接收bi2除以bi1的商和余数
        BigInteger result[] = bi2.divideAndRemainder(bi1);
        System.out.println("bi2除以bi1的商: " + result[0] + ","+"bi2除以bi1的余数：" + result[1]);
    }
}

 */


/*
import java.math.BigDecimal;

public class Example03 {
    public static void main(String[] args) {
        BigDecimal bd1 = new BigDecimal("0.001");  // 创建BigDecimal对象
        BigDecimal bd2 = BigDecimal.valueOf(0.009);// 创建BigDecimal对象
        System.out.println("bd2与bd1的和: " + bd2.add(bd1));
        System.out.println("bd2与bd1的差: " + bd2.subtract(bd1));
        System.out.println("bd2与bd1的积: " + bd2.multiply(bd1));
        System.out.println("bd2与bd1的商: " + bd2.divide(bd1));
        System.out.println("bd2与bd1之间的较大值: " + bd2.max(bd1));
        System.out.println("bd2与bd1之间的较小值: " + bd2.min(bd1));
    }
}

 */


/*
import java.util.Date;

public class Example03 {
    public static void main(String[] args) {
        // 创建表示当前时间的Date对象
        Date date1 = new Date();
        // 获取当前时间后1秒的时间
        Date date2 = new Date(System.currentTimeMillis() + 1000);
        System.out.println(date1);
        System.out.println(date2);
    }
}


 */

/*
import java.util.Calendar;

public class Example03 {
    public static void main(String[] args) {
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);       // 获取当前年份
        int month = calendar.get(Calendar.MONTH) + 1; // 获取当前月份
        int date = calendar.get(Calendar.DATE);       // 获取当前日
        int hour = calendar.get(Calendar.HOUR);       // 获取时
        int minute = calendar.get(Calendar.MINUTE);   // 获取分
        int second = calendar.get(Calendar.SECOND);   // 获取秒
        System.out.println("当前时间为:" + year + "年 " + month + "月 " + date + "日 " + hour + "时 " + minute + "分 " + second + "秒");
    }
}

 */


/*
import java.util.Calendar;

public class Example03 {
    public static void main(String[] args) {
        // 获取表示当前时间的Calendar对象
        Calendar calendar = Calendar.getInstance();
        // 设置指定日期
        calendar.set(2021, 1, 1);
        // 为指定日期增加时间
        calendar.add(Calendar.DATE, 100);
        // 返回指定日期的年
        int year = calendar.get(Calendar.YEAR);
        // 返回指定日期的月
        int month = calendar.get(Calendar.MONTH) + 1;
        // 返回指定日期的日
        int date = calendar.get(Calendar.DATE);
        System.out.println("计划竣工日期为:" + year + "年" + month + "月" + date + "日");
    }
}

 */

/*
import java.time.Instant;

public class Example03 {
    public static void main(String[] args) {
        //  Instant 类的时间戳类从1970-01-01 00:00:00 截止到当前时间的毫秒值
        Instant now = Instant.now();
        System.out.println("从系统获取的当前时刻为：" + now);
        Instant instant = Instant.ofEpochMilli(1000 * 60 * 60 * 24);
        System.out.println("计算机元年增加1000 * 60 * 60 * 24毫秒数后为："
                + instant);
        Instant instant1 = Instant.ofEpochSecond(60 * 60 * 24);
        System.out.println("计算机元年增加60 * 60 * 24秒数后为："
                + instant1);
        System.out.println("获取的秒值为："
                + Instant.parse("2007-12-03T10:15:30.44Z").getEpochSecond());
        System.out.println("获取的纳秒值为："
                + Instant.parse("2007-12-03T10:15:30.44Z").getNano());
        System.out.println("从时间对象获取的Instant实例为：" +
                Instant.from(now));
    }
}


 */

/*
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class Example03 {
    public static void main(String[] args) {
        //获取日期时分秒
        LocalDate now = LocalDate.now();
        LocalDate of = LocalDate.of(2015, 12, 12);
        System.out.println("1. LocalDate的获取及格式化的相关方法--------");
        System.out.println("从LocalDate实例获取当前的年份是：" + now.getYear());
        System.out.println("从LocalDate实例获取当前的月份是："
                + now.getMonthValue());
        System.out.println("从LocalDate实例获取当天为本月的第几天："
                + now.getDayOfMonth());
        System.out.println("将获取到的Loacaldate实例格式化后是："
                + now.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日")));
        System.out.println("2. LocalDate判断的相关方法----------------");
        System.out.println("判断日期of是否在now之前：" + of.isBefore(now));
        System.out.println("判断日期of是否在now之后：" + of.isAfter(now));
        System.out.println("判断日期of和now是否相等：" + now.equals(of));
        System.out.println("判断日期of是否是闰年：" + of.isLeapYear());
        //给出一个符合默认格式要求的日期字符串
        System.out.println("3. LocalDate解析以及加减操作的相关方法---------");
        String dateStr = "2020-02-01";
        System.out.println("把日期字符串解析成日期对象的结果是："
                + LocalDate.parse(dateStr));
        System.out.println("将LocalDate实例年份加1后的结果是："
                + now.plusYears(1));
        System.out.println("将LocalDate实例天数减10后的结果是："
                + now.minusDays(10));
        System.out.println("将LocalDate实例的年份设置为2014后的结果是："
                + now.withYear(2014));
    }
}

 */

/*
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

public class Example03 {
    public static void main(String[] args) {
        // 获取当前时间，包含毫秒数
        LocalTime time = LocalTime.now();
        LocalTime of = LocalTime.of(9,23,23);
        System.out.println("从LocalTime获取的小时为："+time.getHour());
        System.out.println("将获取到的LoacalTime实例格式化为："+
                time.format(DateTimeFormatter.ofPattern("HH:mm:ss")));
        System.out.println("判断时间of是否在now之前："+of.isBefore(time));
        System.out.println("将时间字符串解析为时间对象后为："+
                LocalTime.parse("12:15:30"));
        System.out.println("从LocalTime获取当前时间，不包含毫秒数："+
                time.withNano(0));
    }
}


 */

/*
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Example03 {
    public static void main(String[] args) {
        //获取系统当前年月日时分秒
        LocalDateTime now = LocalDateTime.now();
        System.out.println("获取的当前日期时间为:"+now);
        System.out.println("将目标LocalDateTime转换为相应的LocalDate实例:"+
                now.toLocalDate());
        System.out.println("将目标LocalDateTime转换为相应的LocalTime实例:"+
                now.toLocalTime());
        //指定格式
        DateTimeFormatter ofPattern = DateTimeFormatter.ofPattern
                ("yyyy年MM月dd日 HH时mm分ss秒");
        System.out.println("格式化后的日期时间为:"+now.format(ofPattern));
    }
}

 */


/*
import java.time.Duration;
import java.time.LocalTime;

public class Example03 {
    public static void main(String[] args) {
        LocalTime start = LocalTime.now();
        LocalTime end = LocalTime.of(20,13,23);
        Duration duration = Duration.between(start, end);
        //间隔的时间
        System.out.println("时间间隔为："+duration.toNanos()+"纳秒");
        System.out.println("时间间隔为："+duration.toMillis()+"毫秒");
        System.out.println("时间间隔为："+duration.toHours()+"小时");
    }
}


 */

/*
import java.time.LocalDate;
import java.time.Period;

public class Example03 {
    public static void main(String[] args) {
        LocalDate birthday = LocalDate.of(2018, 12, 12);
        LocalDate now = LocalDate.now();
        //计算两个日期的间隔
        Period between = Period.between(birthday, now);
        System.out.println("时间间隔为"+between.getYears()+"年");
        System.out.println("时间间隔为"+between.getMonths()+"月");
        System.out.println("时间间隔为"+between.getDays()+"天");
    }
}

 */


/*
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;

public class Example03 {
    public static void main(String[] args) throws ParseException {
        // 创建Date对象
        Date date = new Date();
        // Full格式的日期格式器对象
        DateFormat fullFormat =
                DateFormat.getDateInstance(DateFormat.FULL);
        // LONG格式的日期格式器对象
        DateFormat longFormat =
                DateFormat.getDateInstance(DateFormat.LONG);
        // MEDIUM格式的日期/时间 格式器对象
        DateFormat mediumFormat = DateFormat.getDateTimeInstance(
                DateFormat.MEDIUM, DateFormat.MEDIUM);
        // SHORT格式的日期/时间格式器对象
        DateFormat shortFormat = DateFormat.getDateTimeInstance(
                DateFormat.SHORT, DateFormat.SHORT);
        // 打印格式化后的日期或者日期/时间
        System.out.println("当前日期的完整格式为：" + fullFormat.format(date));
        System.out.println("当前日期的长格式为：" + longFormat.format(date));
        System.out.println("当前日期的普通格式为：" + mediumFormat.format(date));
        System.out.println("当前日期的短格式为：" + shortFormat.format(date));
    }
}


 */
/*
import java.text.DateFormat;
import java.text.ParseException;

public class Example03 {
    public static void main(String[] args) throws ParseException {
        // 创建LONG格式的DateFormat对象
        DateFormat dt = DateFormat.getDateInstance(DateFormat.LONG);
        // 定义日期格式的字符串
        String str = "2021年05月20日";
        // 输出对应格式的字符串解析成Date对象后的结果
        System.out.println(dt.parse(str));
    }
}

 */

/*
import java.text.SimpleDateFormat;
import java.util.Date;

public class Example03 {
    public static void main(String[] args) {
        // 创建一个SimpleDateFormat对象
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
        // 按SimpleDateFormat对象的日期模板格式化Date对象
        System.out.println(sdf.format(new Date()));
    }
}


 */

/*
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Example03 {
    public static void main(String args[]) throws ParseException {
        String strDate = "2021-03-02 17:26:11.234";     //定义日期时间的字符串
        String pat = "yyyy-MM-dd HH:mm:ss.SSS";         //定义日期时间的模板
        // 创建一个SimpleDateFormat对象
        SimpleDateFormat sdf = new SimpleDateFormat(pat);
        // 将一个包含日期/时间的字符串格式化为Date对象
        Date d = sdf.parse(strDate);
        System.out.println(d);
    }
}


 */
/*
import java.text.NumberFormat;
import java.util.Locale;

public class Example03 {
    public static void main(String[] args) {
        double price = 18.01;   //定义货币
        int number = 1000010000;//定义数字
        //按照当前默认语言环境的货币格式显示
        NumberFormat nf = NumberFormat.getCurrencyInstance();
        System.out.println("按照当前默认语言环境的货币格式显示："
                + nf.format(price));
        //按照指定的语言环境的货币格式显示
        nf = NumberFormat.getCurrencyInstance(Locale.US);
        System.out.println("按照指定的语言环境的货币格式显示："
                + nf.format(price));
        //按照当前默认语言环境的数字格式显示
        NumberFormat nf2 = NumberFormat.getInstance();
        System.out.println("按照当前默认语言环境的数字格式显示："
                + nf2.format(number));
        //按照指定的语言环境的数字格式显示
        nf2 = NumberFormat.getInstance(Locale.US);
        System.out.println("按照指定的语言环境的数字格式显示："
                + nf.format(number));
    }
}


 */